<?php

namespace app\system\controller;

use app\common\base\_Db;
use app\common\controller\CommonController;
use app\common\entity\RequestEntity;
use think\Db;

class Weuser extends CommonController{
    public function ListUser(){
        $param_page = $get_page = input('Page', 1);
        $param_pagesize =  10;
        $get_keyword = new RequestEntity('search_key', '搜索内容', false, 0);
        $where = '1=1 and iden =1';
        if(!empty($get_keyword->text)){
            $where .= ' and nick_name  like "' . $get_keyword->text.'%"';
        }
        $res = Db::name('user')
            ->field([
                'user_id'=>'Id',
                'nick_name'=>'Name',
                'avatar_url'=>'HeaderUrl',
                'gender'=>'Sex',
                'phone_number'=>'Phone',
                //'status'=>'Status',
            ])
            ->where($where)
            ->limit(($param_page - 1) * $param_pagesize, $param_pagesize)
            ->select();
        foreach ( $res as $key => $value){
            $res[$key]['Order'] = $key + 1;
        }
        $int_total_count = count(Db::name('user')
            ->where($where)
            ->select());
        $data['tableData']=$res;
        $data['TotalCount'] = $int_total_count;
        $data['Page'] = (int)$param_page;
        $data['PageSize'] = (int)$param_pagesize;
        _Db::ResponseJson($data);
    }
    public function ItemUser(){
        $WeUserId = new RequestEntity('WeUserId', '用户id', false, 32);
        $res = Db::name('user')
            ->field([
                'nick_name'=>'Name',
                'avatar_url'=>'HeaderUrl',
                'gender'=>'Sex',
                'phone_number'=>'Phone',
                //'status'=>'Status',
                'country'=>'Country',
                'province'=>'Province',
                'city'=>'City',
                'language'=>'Language',
                'sign_return_code'=>'sign_return_code',
                'sign_return_msg'=>'sign_return_msg',
                'sign_contract_id'=>'sign_contract_id',
                'relieve_return_code'=>'relieve_return_code',
                'relieve_return_msg'=>'relieve_return_msg',
                'contract_date'=>'contract_date',
                'relieve_date'=>'relieve_date'
            ])
            ->where('user_id ="'.$WeUserId->text.'"and iden = 1')
            ->find();
        _Db::ResponseJson($res);
    }
}